﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginarium.team;
using System.Xml;
using Imaginarium.jobs.skills;
using Imaginarium.jobs;

namespace Imaginarium.XML
{
    public class XmlLoader
    {
        public static Enemy loadEnemy(int id) {
            int[] arr1 = new int[10];
            Enemy enemy = null;
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(XmlParameters.FILE_ENEMIES);
            XmlNodeList eList = xDoc.GetElementsByTagName(XmlParameters.ENEMIES_LIST);
            if (eList.Count == 0) return enemy;
            XmlNodeList enemies = ((XmlElement)eList[0]).GetElementsByTagName(XmlParameters.ENEMY);
            foreach (XmlElement element in enemies) {
                int enemyId = XmlHelper.getIntByTagname(element, XmlParameters.ENEMY_ID);
                if (id == enemyId) {
                    enemy = new Enemy(element);
                    return enemy;
                }
            }
            return enemy;
        }

        public static Skill loadSkill(int id) {
            Skill skill = null;
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(XmlParameters.FILE_SKILLS);
            XmlNodeList sList = xDoc.GetElementsByTagName(XmlParameters.SKILLS_LIST);
            if (sList.Count == 0) return skill;
            XmlNodeList skills = ((XmlElement)sList[0]).GetElementsByTagName(XmlParameters.SKILL);
            foreach (XmlElement xe in skills) {
                int skillId = XmlHelper.getIntByTagname(xe, XmlParameters.SKILL_ID);
                if (id == skillId)
                {
                    skill = new Skill(xe);
                    return skill;
                }
            }
            return skill;
        }

        public static Job loadJob(int id) {
            Job job = null;
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(XmlParameters.FILE_JOBS);
            XmlNodeList jList = xDoc.GetElementsByTagName(XmlParameters.JOBS_LIST);
            if (jList.Count == 0) return job;
            XmlNodeList jobs = ((XmlElement)jList[0]).GetElementsByTagName(XmlParameters.JOB);
            foreach (XmlElement xe in jobs)
            {
                int jobId = XmlHelper.getIntByTagname(xe, XmlParameters.SKILL_ID);
                if (id == jobId)
                {
                    job = new Job(xe);
                    return job;
                }
            }
            return job;
        }
    }
}
